package com.huwaiwai.jvm.d20200714;

import io.netty.util.HashedWheelTimer;
import io.netty.util.Timeout;

import java.util.concurrent.TimeUnit;

/**
 * @author 歪大哥😁
 * @date 2020-07-14.
 */
public class HashedWheelTimerTest {

    public static void main(String[] args) throws Exception {
        HashedWheelTimer h = new HashedWheelTimer();
        long start = System.currentTimeMillis();
        System.out.println("初始时间" + start);
        Timeout t = h.newTimeout((timeout) -> {
            System.out.println("延迟1000ms执行" + System.currentTimeMillis());
            Thread.sleep(300);
        }, 1000L, TimeUnit.MILLISECONDS);
        h.newTimeout((timeout) -> System.out.println("延迟1100ms执行" + System.currentTimeMillis() + "  相对时间=" + (System.currentTimeMillis() - start)), 1100L, TimeUnit.MILLISECONDS);
        h.newTimeout((timeout) -> System.out.println("延迟1200ms执行" + System.currentTimeMillis() + "  相对时间=" + (System.currentTimeMillis() - start)), 1200L, TimeUnit.MILLISECONDS);
        h.newTimeout((timeout) -> System.out.println("延迟2000ms执行" + System.currentTimeMillis() + "  相对时间=" + (System.currentTimeMillis() - start)), 2000L, TimeUnit.MILLISECONDS);
        Thread.sleep(15_000L);
        h.stop();
    }
}
